<?php
/**
 *
 * @author Strawberry🍓
 * @date 2021-05-21 4:08 下午
 *
 */

namespace app\common\model\tang;


use app\common\impl\Comm;
use app\common\model\CommonBaseModel;
use Jrk\Tree;
class CostType extends CommonBaseModel implements Comm
{

    public function getAdminPageData($param = [], $order = 'id desc')
    {
        // TODO: Implement getAdminPageData() method.

        $where = [
            'status'  => 1
        ];
        $model = $data = self::where($where) ;
        try {
            if (isset($param['cost_name']) && $param['cost_name']){
                $model->where('cost_name','like',"%{$param['cost_name']}%");
             }
            $data = $model->order($order)->select()->toArray();
            $count =$model->count("id");
            if (!empty($data)) {
                foreach ($data as& $v){
                    if(!empty($v['auxiliary'])){
                          $auxiliary = explode(',',$v['auxiliary']);
                          $arr = [] ;
                          foreach ($auxiliary as $v1){
                              switch ($v1){
                                  case 1 :
                                      $arr[] = '部门' ;
                                      break ;
                                  case 2 :
                                      $arr[] = '客户' ;
                                      break ;
                              }
                          }
                        $v['auxiliary'] = implode('+',$arr);
                    }
                }
                unset($v);
                $data = Tree::DeepTree($data,"treeList");
            }
            return parent::ajaxResult($data, $count);
        } catch (\Exception $exception) {
            return parent::ajaxResult([], 0, 100, $exception->getMessage());
        }
    }
    public function subject(){
        return $this->hasOne(SubjectList::class,'id','subject_id');
    }
    public function delById($id)
    {
        // TODO: Implement delById() method.
        return parent::del($id);
    }

    public function doAll($data)
    {
        // TODO: Implement doAll() method.
        return parent::doAllData($data);
    }
}